package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.utils.MapUtil;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class YmtCatalogsIWapper {
	SqlManager manage;

	public YmtCatalogsIWapper() {
		manage = new SqlManager("intpro");
	}


	//获取不重复商品Id 
	public List<Map> selectProductIdBySku(String Sku)throws InterruptedException {
		 List<Map>  ret = manage.getSelectResults(
		            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductIdBySku", Sku);
//		    manage.commit();
		    return ret;
	}
	
	
	//查询Ymt_Catalogs
	public List<YmtCatalogsI> selectCatalogsByProductId(String sProductId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    List<YmtCatalogsI>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductId", sProductId);
//	    manage.commit();
	    return catalogslist;
	}
	
	
	//查询Ymt_Catalogs
	public YmtCatalogsI selectCatalogsByCatalogId(String catalogId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    List<YmtCatalogsI>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByCatalogId", catalogId);
//	    manage.commit();
	    return catalogslist.get(0);
	}
	
	
	public List<YmtCatalogsI> selectCatalogsByCatalogIdforList(String catalogId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    List<YmtCatalogsI>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByCatalogId", catalogId);
//	    manage.commit();
	    return catalogslist;
	}
	
	
	
	//查询Ymt_Catalogs
	public List<Map> selectCatalogsByProductIdforMap(String sProductId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductIdforMap", sProductId);
//	    manage.commit();
	    return catalogslist;
	}
	
	
	
	public List<Map> selectCatalogAttributeByCatalogId(String catalogId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogAttributeByCatalogId", catalogId);
//	    manage.commit();
	    return catalogslist;
	}
	
	
	
	
/*    
 * sUser=wesper,
    iLimitNum=30,
    fFlight=0.00,
    sProductId=067f6d91-0a59-4fb5-b705-9f5c2469f788,
    IsNew=true,
    iNum=3,
    BondedQuantity=1,
    iUserId=3383,
    dAddTime=2016-06-1514: 11: 55.837,
    iExpire=36524,
    iCatalogType=2,
    sCatalogId=e920929b-53bb-4b84-af89-12232b006741,
    iAcceptReturn=0,
    DataVersion=[
        B@a9cd3b1,
        fQuotePrice=100.00,
        iAction=0,
        iCatalogStatus=5,
        sSKU=ceshi100,
        iSKUType=0
    }*/
	public List<Map> selectCatalogsByUserIdandSku (Integer uSerId,String Sku)throws InterruptedException{
		@SuppressWarnings("unchecked")
		Map <String,Object>mm=new HashMap<String,Object>();
		mm.put("uSerId", uSerId);
		mm.put("Sku", Sku);
		List <Map> catalogslist=manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByUserIdandSku", mm);
//		manage.commit();
		return catalogslist;
	}

	//查询Ymt_ProductPicture
	public List<Map> selectProductPictureByProductId(String sProductId) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductPictureByProductId", sProductId);
//	    manage.commit();
	    return catalogslist;
	}
	
	//查询Ymt_ProductDescConfigWord
	public List<Map> selectProductDescConfigWordByProductId(String sProductId) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectProductDescConfigWordByProductId", sProductId);
//	    manage.commit();
	    return catalogslist;
	}

	//更新
	public int updatestocknumByCatalogId(int iNum , String productID) throws InterruptedException {
	    Map m = new HashMap();
	    m.put("iNum", iNum);
	    m.put("productId", productID);
	    int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updatestocknumByCatalogId", m);
	    manage.commit();
	    // manage.close();
	    return i;
	}
	
	
	
	public int updatePreSaleByProductId(int preSale , String productID) throws InterruptedException {
	    Map m = new HashMap();
	    m.put("IsPreSale", preSale);
	    m.put("productId", productID);
	    int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updatePreSaleByProductId", m);
	    manage.commit();
	    // manage.close();
	    return i;
	}
	
	
	//查询
	public List<Map> selectCatalognamesforonelogs(Map m) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalognamesforonelogs", m);
//	    manage.commit();
	    return catalogslist;
	}
	
	//查询
	public List<Map> selectCatalognamesfortwologs(Map m) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalognamesfortwologs", m);
//	    manage.commit();
	    return catalogslist;
	}
	
	//查询商品最大单价
	public List<Map> selectMaxfQuotePrice(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectMaxfQuotePrice", sproductid);
//	    manage.commit();
	    return catalogslist;
	}
	
	//查询商品最小单价
	public List<Map> selectMinfQuotePrice(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectMinfQuotePrice", sproductid);
//	    manage.commit();
	    return catalogslist;
	}
	
	
	
	
	//查询商品最小单价
	public Map selectAllMinPrice(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults( "com.ymttest.database.mapping.YmtCatalogsIMapper.selectAllMinPrice", sproductid);
	    return catalogslist.get(0);
	}
	
	public List<Map> selectNewPriceWithout0(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults( "com.ymttest.database.mapping.YmtCatalogsIMapper.selectNewPriceWithout0", sproductid);
	    return catalogslist;
	}
	
	
	public List<Map> selectVipPriceWithout0(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults( "com.ymttest.database.mapping.YmtCatalogsIMapper.selectVipPriceWithout0", sproductid);
	    return catalogslist;
	}
	
	
	//查询商品最da单价
	public Map selectAllMaxPrice(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults( "com.ymttest.database.mapping.YmtCatalogsIMapper.selectAllMaxPrice", sproductid);
	    return catalogslist.get(0);
	}
	
	
	
	
	
	//查询商品库存总数
	public List<Map> selectSumStock(String sproductid) throws InterruptedException {
	    List<Map>  catalogslist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectSumStock", sproductid);
//	    manage.commit();
	    return catalogslist;
	}
	
	public int updateCatalogTypeByProductId(String productId,int catalogType){
		int i = manage.update("com.ymttest.database.mapping.YmtCatalogsIMapper.updateCatalogTypeByProductId", MapUtil.hashMap("sProductId", productId,"iCatalogType",catalogType));
		manage.commit();
		return i;
	}
	
	
	
	//根据商品id和sku查询
	public List<Map> selectCatalogsByProductIdandSku(String sProductId , String sSKU) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    Map m = new HashMap();
	    m.put("sProductId", sProductId);
	    m.put("Sku", sSKU);
	    List<Map>  sProductIdlist = manage.getSelectResults(
	            "com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogsByProductIdandSku", m);
//	    manage.commit();
	    return sProductIdlist;
	}
	
	
	//根据商品id和sku查询
	public List<Map> selectCatalogPropsByCatalogId(String catalogId) throws InterruptedException {
	    @SuppressWarnings("unchecked")
	    Map m = new HashMap();
	    m.put("sCatalogId", catalogId);
	    List<Map>  sCatalogPropslist = manage.getSelectResults("com.ymttest.database.mapping.YmtCatalogsIMapper.selectCatalogPropsByCatalogId", m);
	    return sCatalogPropslist;
	}
	
	
	
	public static void main(String args[]) {
	    try {
	    	List<Map> aCatalogsIs = new YmtCatalogsIWapper().selectVipPriceWithout0("52e3eeae-8458-436a-9691-3c9cf163e65a");
	    	System.out.println(new YmtCatalogsIWapper().selectCatalogPropsByCatalogId("39c39658-fd98-48bb-8f41-49c946ee63cc").toString());
	    	System.out.println(new YmtCatalogsIWapper().selectCatalogPropsByCatalogId("39c39658-fd98-48bb-8f41-49c946ee63cc").size());
	    	System.out.println(new YmtCatalogsIWapper().selectCatalogPropsByCatalogId("c91c03be-6182-4161-b233-7cd307bccd73").size());
	    } catch (InterruptedException e) {
	        e.printStackTrace();
	    }
	}
	
}
